package org.example.work.service;

import org.example.work.Mapper.Busermapper;
import org.example.work.Mapper.Ordersmapper;
import org.example.work.Mapper.Usermapper;
import org.example.work.entity.buser;
import org.example.work.entity.orders;
import org.example.work.entity.user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class updata {
    @Autowired
    private Busermapper bu;

    @Autowired
    private Ordersmapper orderMapper;

    @Transactional
    public void updateUserAndOrder() {
        // 更新用户信息
        buser buser = new buser();

String a="小明";
String b="456";
        bu.updatePassword(a,b);

        // 更新订单信息
        orders order = new orders();
int c=2;
int d=356;
        orderMapper.update(c,d);

//         模拟异常，触发事务回滚
        if (true) {
            throw new RuntimeException("Simulated Exception");
        }
//        if (false) {
//            throw new RuntimeException("Simulated Exception");
//        }
    }
}
